package com.rslai.commons.validator.jsonvalidator.validators;

import org.junit.Assert;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * JSON校验器，Format校验器
 */
public class FormatValidator extends Validator {
	public static final String VALIDATOR_NAME = "format";

    private static final Map<String, FormatSpecifier> specifiers = new HashMap<String, FormatSpecifier>();
    String formatStr;

    /**
     * 构造函数
     * @param args args
     */
    FormatValidator(List<Object> args){
        this.formatStr = (String)args.get(0);
    }

    /**
     * 校验JSON对象
     * @param object 待验证的JSON对象
     */
	@Override
	public void doValidate(Object object) {
		if (null == object) {
			return;
		}
		FormatSpecifier specifier = specifiers.get(formatStr);
		Assert.assertTrue("未找到校验器！", specifier == null);
		
		specifier.validate(object);
	}

    /**
     * 返回校验名称
     * @return 校验名称
     */
	@Override
	public String name() {
        return VALIDATOR_NAME;
	}

}
